<?php
/**
 * Custom exception class definitions
 *   
 * @author Sean Crystal <seancrystal@gmail.com>
 * @package MVP-PHP
 */
     
/**
 * Thrown when an attempt is made to read a write-only property
 * @package MVP-PHP
 * @subpackage Exceptions
 */    
class WriteOnlyPropertyException extends Exception
{
	public function __construct($class, $name)
	{
		parent::__construct();
		
		$this->message = "{$class}::{$name} is a write-only property";
	}
}

/**
 * Thrown when an attempt is made to write a read-only property
 * @package MVP-PHP
 * @subpackage Exceptions
 */    
class ReadOnlyPropertyException extends Exception
{
	public function __construct($class, $name)
	{
		parent::__construct();
		
		$this->message = "{$class}::{$name} is a read-only property";
	}
}

/**
 * Thrown when an attempt is made to access a property that is inaccessible or does not exist
 * @package MVP-PHP
 * @subpackage Exceptions
 */    
class InaccessiblePropertyException extends Exception
{
	public function __construct($class, $name)
	{
		parent::__construct();
		
		$this->message = "{$class}::{$name} is inaccessible";
	}
}

/**
 * Thrown when loading a class by name fails because the class does not exist
 * @package MVP-PHP
 * @subpackage Exceptions
 */  
class ClassNotFoundException extends Exception
{
	public function __construct($class)
	{
		parent::__construct();
		
		$this->message = "Class {$class} cannot be found";
	}	
}

/**
 * Base class for Contract exceptions
 * @package MVP-PHP
 * @subpackage Exceptions
 */  
class ContractException extends Exception
{
}

/**
 * Thrown when a Contract::Precondition fails
 * @package MVP-PHP
 * @subpackage Exceptions
 */  
class PreconditionFailedException extends ContractException
{
	public function __construct($message, $code = 0)
	{
		parent::__construct($message, $code);
		
		$this->message = "Precondition Failed: ". $this->getMessage();
	}
}

/**
 * Thrown when a Contract::Postcondition fails
 * @package MVP-PHP
 * @subpackage Exceptions
 */ 
class PostconditionFailedException extends ContractException
{
	public function __construct($message, $code = 0)
	{
		parent::__construct($message, $code);
		
		$this->message = "Postcondition Failed: ". $this->getMessage();
	}
}

/**
 * Thrown when a Contract::Invariant fails
 * @package MVP-PHP
 * @subpackage Exceptions
 */ 
class InvariantFailedException extends ContractException
{
	public function __construct($message, $code = 0)
	{
		parent::__construct($message, $code);
		
		$this->message = "Invariant Failed: ". $this->getMessage();
	}
}

/**
 * Thrown when a Contract::Assertion fails
 * @package MVP-PHP
 * @subpackage Exceptions
 */ 
class AssertionFailedException extends ContractException
{
	public function __construct($message, $code = 0)
	{
		parent::__construct($message, $code);
		
		$this->message = "Assertion Failed: ". $this->getMessage();
	}
}

/**
 * Thrown when the dependency injector tries to get an instance of an unbound abstract class
 * @package MVP-PHP
 * @subpackage Exceptions
 */ 
class UnboundDependencyException extends Exception
{
}

/**
 * Thrown when a request is made for a page that does not exist in the app
 * @package MVP-PHP
 * @subpackage Exceptions
 */ 
class PageNotFoundException extends Exception
{
	public function __construct($mod, $page)
	{
		parent::__construct();
		
		$this->message = "Page /{$mod}/{$page} could not be found";
	}
}

/**
 * Thrown when a Page object tries to render, but has no iViewRenderer specified
 * @package MVP-PHP
 * @subpackage Exceptions
 */ 
class PageMissingRendererException extends Exception
{
	public function __construct($pageClass)
	{
		parent::__construct();
		
		$this->message = "{$pageClass} has no renderer";
	}
}



?>